package com.jxau.mall.user.controller;

import com.jxau.mall.common.util.ResponseVO;
import com.jxau.mall.user.entity.UserReceiveAddress;
import com.jxau.mall.user.model.UserReceiveAddressDTO;
import com.jxau.mall.user.service.IUserReceiveAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: shop
 * @description: 获取收件地址服务控制器类
 * @author: guojiani
 * @create: 2025-04-24 21:52
 **/
@RestController
@RequestMapping("/user/address")
public class UserReceiveAddressController {
    @Autowired
    private IUserReceiveAddressService userReceiveAddressService;

    /**
     * 添加地址
     * @param userReceiveAddress
     * @return
     */
    @PostMapping("/save")
    public ResponseVO save(@RequestBody UserReceiveAddress userReceiveAddress){
        userReceiveAddressService.save(userReceiveAddress);
        return ResponseVO.success();
    }

    /**
     * 获取用户地址
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseVO<List<UserReceiveAddressDTO>> list(@PathVariable Long id){
        List<UserReceiveAddressDTO> list = userReceiveAddressService.listByUserId(id);
        return ResponseVO.success(list);
    }
}
